/*
 * slave_client.h
 *
 *  Created on: 2018年11月5日
 *  Author: Degang.Wu (windragon@126.com)
 *  Desc:
 */

#ifndef SLAVE_CLIENT_H_
#define SLAVE_CLIENT_H_

#include "enc_listener.h"

namespace hiapp
{

typedef enum
{
	BWENC_SBOARD_INVALID = 0,

	BWENC_SBOARD_IDEL,
	BWENC_SBOARD_RUNNING,

	BWENC_SBOAD_NB
}eSBOARD_WORK_STS;

class SlaveClient: public Listener
{
public:
	SlaveClient(U16 _port);
	virtual ~SlaveClient();

protected:
	virtual void onRun();
	virtual int process(pU8 msg, int sock);

	int	init_network();
	void update_cfg(pU8 msg);
	void update_intcfg(pU8 msg);
	void handle_sync_msg(pU8 msg);
	void response_info(int sock);

	int reg2mst();

	int sync_chlcfg_shmem(int chlidx, pENC_CHLSET chlset);

	virtual void onStop();

	static void check_network_change(void* param);
	void 	do_check_network();

	void 	sync_time(U32 time_sec);

private:
	int	sub_idx;
	char sub_ipaddr[64];
	eSBOARD_WORK_STS	sbsts;

	pthread_mutex_t		chk_net_mutex;
	pthread_cond_t		chk_net_cond;
};

} /* namespace hiapp */

#endif /* SLAVE_CLIENT_H_ */
